﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcDemo.Control
{
    public class MvcControlTextbox:MvcControlInput
    {
        public MvcControlTextbox(HtmlHelper htmlHelper)
            : base(htmlHelper)
        { 
            
        }

        /// <summary>
        /// TextBox控件要显示的内容
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override string InnerWriteHtml()
        {
            string result = string.Empty;
            if (this.UsingMode == MvcControlUsingModes.Editable)
            {
                TagBuilder tagInput = new TagBuilder("input");
                tagInput.Attributes["type"] = "text";
                tagInput.Attributes["name"] =Name;
                tagInput.AddCssClass("hl_textBox");
                tagInput.Attributes["value"] = Value;
                result = tagInput.ToString();
            }
            else
            {
                TagBuilder tagSpan = new TagBuilder("span");
                tagSpan.AddCssClass("hl_display");
                tagSpan.Attributes["name"] = Name;
                tagSpan.InnerHtml = Value;
                result = tagSpan.ToString();
            }

            return result;
        }
    }
}